using UnityEngine;

public class INT_RunComponentOnChatIndex : MonoBehaviour
{
	public INT_Chat TargetChatStarter;

	public CHATBOXTEXT TargetChat;

	public ChatboxManager ChatManager;

	[Space(7.5f)]
	[Header("WARNING! This component is removed once ran")]
	public Component TargetComponent;

	[Space(5f)]
	public string MethodName;

	[Space(7.5f)]
	public int ChatTextIndexToPlay;

	[Header("For text that requires the player to interact multiple times")]
	public int AdditionalTextIndexToPlay;

	private bool CurrentActiveChatIsTarget;

	private bool hasRan;

	private void Update()
	{
		if ((Object)(object)ChatManager.storedchatboxtext == (Object)(object)TargetChat)
		{
			CurrentActiveChatIsTarget = true;
		}
		if (CurrentActiveChatIsTarget && ChatManager.CurrentTextIndex == ChatTextIndexToPlay && ChatManager.CurrentAdditionalTextIndex == AdditionalTextIndexToPlay && TargetChatStarter.FinishedText && !hasRan && (Object)(object)TargetComponent != (Object)null && ((object)TargetComponent).GetType().GetMethod(MethodName) != null)
		{
			hasRan = true;
			((object)TargetComponent).GetType().GetMethod(MethodName).Invoke(TargetComponent, null);
			Object.Destroy((Object)(object)this, 0.5f);
		}
	}
}
